﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Waterfood.FolderSizeViewer
{
    internal static class Extensions
    {
        public static String ToHumanReadable(this Int64 value)
        {
            String[] Units = { "B", "KB", "MB", "GB", "TB" };
            Decimal number = value;
            Int32 i;
            for (i = 0; i < Units.Length; i++)
            {
                if (number >= 1000)
                {
                    number /= 1000;
                }
                else
                {
                    break;
                }
            }
            String result = String.Format("{0:G5} {1}", number, Units[i]);
            return result;
        }
    }
}
